package net.homeip.mmhg.security;

import net.homeip.mmhg.domain.Team;

import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
 * Supports all security operations. 
 *
 * @author ilya gerasimov
 */
@Service
public class SecurityManager {
	
	public Team getCurrentUser() {
		if ( (SecurityContextHolder.getContext() == null) || 
				(SecurityContextHolder.getContext().getAuthentication() == null) ||
				(SecurityContextHolder.getContext().getAuthentication().getPrincipal() == null) ){
			return null;
		}
		
		return ((Team2UserDetailsAdapter) SecurityContextHolder.getContext()
											  .getAuthentication()
											  .getPrincipal())
											  .getTeam();
	}
}
